import { _decorator, Button } from 'cc';
import { BasePanel } from '../../../../scripts/libs/ui/BasePanel';
import { BindButton } from '../../../../scripts/libs/rxjs/cc3/BindButton';
import { lm } from '../../LobbyManager';
import { udm } from '../../../../scripts/managers/UserDataManager';
import { ShopPage } from '../LobbyPanel/ShopPage/ShopPage';
import { thinking_sdk_m } from '../../../../scripts/managers/SDK/ThinkingCocosSDKManager';
import { gm } from '../../../../scripts/managers/GameManager';
const { ccclass, property } = _decorator;

@ccclass('ShopPanel')
export class ShopPanel extends BasePanel {

    @property(Button)
    closeButton: Button = null;

    @property(ShopPage)
    shopPage: ShopPage = null;

    willBind(): void {
        gm.currentAdsType.value = 'AdGiveCoin';
        gm.currentAdsOpenUI.value = 'ShopPanel';
        lm.shopPanelOpened.value = true;
    }

    useObserves() {
        return [
            BindButton(this.closeButton).subscribe(this.closeButtonClicked.bind(this)),
        ];
    }

    onDestroyView(): void {
        lm.shopPanelOpened.value = false;
    }

    onLoadView(): void {
        if (this.shopPage.freeAdsAvailable()) {
            thinking_sdk_m.requestTrack('Ads_Show', {
                AdsType: gm.currentAdsType.value,
                OpenUI: gm.currentAdsOpenUI.value,
                IsNew: udm.isNew.value
            });
        }
    }

    closeButtonClicked() {
        ShopPanel.CloseProcess(null, 'close');
    }
}

